﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Prism.Events;
using SoonCode.FocusTest.Events;
using SoonCode.FocusTest.Models;
using SoonCode.FocusTest.Utils;
using SoonCode.FocusTest.ViewModels;
using MessageBox = HandyControl.Controls.MessageBox;

namespace SoonCode.FocusTest.Views
{
    /// <summary>
    /// TestPrintView.xaml 的交互逻辑
    /// </summary>
    public partial class TestPrintView : UserControl
    {
        private IEventAggregator aggregator;
        private TestPrintViewModel dataContext;

        public TestPrintView(IEventAggregator aggregator)
        {
            this.aggregator = aggregator;
            InitializeComponent();
            this.aggregator.GetEvent<PrintTestResultEvent>().Subscribe(PrintTestResult);
            dataContext=(TestPrintViewModel)DataContext;
        }

        public void PrintTestResult(EventInfo eventInfo)
        {   
            if (eventInfo.Type != TestPrintModel.type) return;
            dataContext.SetData((TestPrintModel)eventInfo.Data["model"]);
            UpdateLayout();
            try
            {
                PrintUtil.Print(this, "专注力评测结果", 1);
            }
            catch (Exception e)
            {
                DialogUtil.Show(this.aggregator,e.Message);
            }
            
        }
    }
}
